﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace XDesigner.AppFramework.Actions
{
    public class AppActionList : System.Collections.CollectionBase 
    {
        public AppActionList()
        {
        }

        public AppAction this[int index]
        {
            get
            {
                return (AppAction)this.List[index];
            }
        }

        public AppAction this[string name]
        {
            get
            {
                if (name == null || name.Trim().Length == 0)
                {
                    return null;
                }
                name = name.Trim();
                foreach (AppAction act in this)
                {
                    if (string.Compare(act.Name , name, true) == 0)
                    {
                        return act;
                    }
                }
                return null;
            }
        }

        public AppAction this[Type type]
        {
            get
            {
                if (type == null)
                {
                    return null;
                }

                foreach (AppAction act in this)
                {
                    if (act.GetType().Equals(type))
                    {
                        return act;
                    }
                }
                return null;
            }
        }

        private AppFrameworkClass _Framework = null;

        internal AppFrameworkClass Framework
        {
            get
            {
                return _Framework; 
            }
            set
            {
                if (_Framework != value)
                {
                    _Framework = value;
                    if (_Framework != null)
                    {
                        foreach (AppAction action in this)
                        {
                            action.Framework = _Framework;
                        }
                    }
                }
            }
        }

        public int Add(AppAction action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
            if (action != null)
            {
                action.Framework = _Framework;
            }
            return this.List.Add(action);
        }

        public void Remove(AppAction action)
        {
            this.List.Remove(action);
        }


    }
}
